﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Marmat.Common.Http
{

    /// <summary>
    /// 日志过滤器
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Method)]
    public class LoggingFilterAttribute : Attribute, IHttpApiFilter
    {
        /// <summary>
        /// 是否启用日志服务。
        /// </summary>
        public bool Enable { get; set; } = true;

        internal virtual Task OnWriteLogAsync(ApiActionContext context, LogMessage logMessage)
        {
            return WriteLogAsync(context, logMessage);
        }

        protected virtual Task WriteLogAsync(ApiActionContext context, LogMessage logMessage)
        {
            string message = logMessage.ToIndentedString(spaceCount: 4);
            System.Diagnostics.Debug.WriteLine(message);
            return default;
        }
    }
}
